////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008 Michiel Helvensteijn                                    //
//                                                                            //
// This file is part of the Mist compiler.                                    //
//                                                                            //
// The Mist compiler is free software: you can redistribute it and/or modify  //
// it under the terms of the GNU General Public License as published by       //
// the Free Software Foundation, either version 3 of the License, or          //
// (at your option) any later version.                                        //
//                                                                            //
// The Mist compiler is distributed in the hope that it will be useful,       //
// but WITHOUT ANY WARRANTY; without even the implied warranty of             //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              //
// GNU General Public License for more details.                               //
//                                                                            //
// You should have received a copy of the GNU General Public License          //
// along with the Mist compiler.  If not, see <http://www.gnu.org/licenses/>. //
////////////////////////////////////////////////////////////////////////////////

#ifndef ASSERT_HPP
#define ASSERT_HPP

/******************************************************************************
 * Includes                                                                   *
 ******************************************************************************/

#define BOOST_ENABLE_ASSERT_HANDLER

#include <boost/assert.hpp>

#include <exception>
using std::exception;

#include <string>
using std::string;

#include <cstdlib>

/******************************************************************************
 * assert Macro                                                               *
 ******************************************************************************/

#ifdef assert
	#undef assert
#endif

#define assert(expr) ((expr) ? ((void)0) : (::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__), abort()))

/******************************************************************************
 * AssertionFailure Exception Class                                           *
 ******************************************************************************/

class AssertionFailure : public virtual exception {
	public:
		
		AssertionFailure(string expression, string function, string file, long line);
		
		~AssertionFailure() throw() {}
		
		const char* what() const throw();
		
		const string& expression() const;
		
		const string& function() const;
		
		const string& file() const;
		
		long line() const;
	
	private:
		
		string _expression;
		string _function;
		string _file;
		long   _line;
};

/******************************************************************************
 * Disabling Asserts:                                                         *
 ******************************************************************************/

// #define BOOST_DISABLE_ASSERTS // Uncomment to disable asserts

#endif // ASSERT_HPP
